<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Mua~亲亲宠————修改密码</title>
<link rel="stylesheet" href="css/style.css" />

<link rel="stylesheet" href="css/bootstrap.css" />

<link rel="stylesheet" href="css/bootstrapValidator.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>
</head>

<body>
	<%@ include file="/WEB-INF/jsp/top.jspf"%>
	<div class="title"></div>
	<div class="container  col-sm-offset-2  col-sm-8">
		<div class="page-header" style="color:#000099">
			<h3>修改密码</h3>
		</div>
		<form id="pwdForm" class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">旧密码</label>
				<div class="col-sm-5">
					<input type="password" name="oldPassword" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">密码</label>
				<div class="col-sm-5">
					<input type="password" name="password" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">确认密码</label>
				<div class="col-sm-5">
					<input type="password" name="repassword" class="form-control" />
				</div>
			</div>
			<div class="col-sm-offset-2 col-sm-3">
				<button type="button" class="btn btn-info"
					onclick="checkAndSubmit()">确认信息</button>
			</div>
		</form>

	</div>
	<script>
		$(document).ready(function() {
			$('#pwdForm').bootstrapValidator({
				message : 'This value is not valid',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				fields : {
					oldPassword : {
						message : '',
						validators : {
							notEmpty : {
								message : '密码不能为空'
							},
							stringLength : {
								min : 8,
								max : 30,
								message : '密码最少8位，最多30位'
							},
							regexp : {
								regexp : /^[a-zA-Z0-9_]+$/,
								message : '密码只能由字母，数字，下划线组成'
							}

						}
					},
					password : {
						message : '',
						validators : {
							notEmpty : {
								message : '密码不能为空'
							},
							stringLength : {
								min : 8,
								max : 30,
								message : '密码最少8位，最多30位'
							},
							regexp : {
								regexp : /^[a-zA-Z0-9_]+$/,
								message : '密码只能由字母，数字，下划线组成'
							}

						}
					},
					repassword : {
						message : '',
						validators : {
							notEmpty : {
								message : '确认密码不能为空'
							},
							stringLength : {
								min : 8,
								max : 30,
								message : '密码最少8位，最多30位'
							},
							identical : {
								field : 'password',
								message : '两次密码不同请重新输入'
							}
						}
					}
				}
			});

		});
		function checkAndSubmit() {
			$("#pwdForm").bootstrapValidator('validate');//提交验证  
			if ($("#pwdForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码  
				$.ajax({
					url : "user/updatePwd.do",
					data : $("#pwdForm").serialize(),
					type : "POST",
					success : function(result) {
						//请求成功时
						if (result.msg == 'success') {
							$(".modal-body").html("修改密码成功！点击确定前往重新登录");
							$("#topModal").modal("show");
							$("#topModal").on('hidden.bs.modal', function() {
								var gotoURL = "login.html";
								window.location.href = gotoURL;
							});
						} else if (result.msg == 'error') {
							$(".modal-body").html(result.errorMsg);
							$("#topModal").modal("show");
						}
					},
					error : function() {
						//请求失败时
						$(".modal-body").html("修改失败");
						$("#topModal").modal("show");
					}
				});
			}
		}
	</script>
</body>
</html>
